function normalizeName(name: string) {
    return name.replace(/([A-Z|a-z]+[A-Z0-9]*)-?/g, ($0: string, $1: string) => {
        return $1?.length > 0 ? `${$1[0].toUpperCase()}${$1.slice(1)}` : $1;
    });
}

function normalizeContent(content: string | Buffer) {
    return (
        content
            ?.toString()
            ?.replace(/xml:space/, 'xmlSpace')
            .replace(/ width="[^"]*"/, '')
            .replace(/ height="[^"]*"/, '')
            .replace(/ fill="#?\w+"/g, '')
            .replace(/ fill-rule="#?\w+"/g, '')
            .replace(/ clip-rule="#?\w+"/g, '')
            .replace(/\s{2,}/g, ' ')
            .replace(/ class="\w+"/g, '')
            .replace(/<style>.*<\/style>/g, (match) =>
                match.replace(/<style>/g, '<style>{ `').replace(/<\/style>/g, '` }</style>'),
            )
            /**
             * replace data with react props
             */
            .replace(
                /viewBox/,
                `
             fill={isHover ? hoverFill : fill}
             height={height || size}
             width={width || size}
             onClick={onClick}
             style={style}
             className={className}
             {...otherProps}
             onMouseEnter={() => isEnableHoverState && setIsHover(true)}
             onMouseLeave={() => isEnableHoverState && setIsHover(false)}
             viewBox`,
            )
            .replace(/[a-zA-Z0-9]+(-[a-zA-Z0-9]+)+=/gi, ($0: string, $1: string, $2) => {
                if ($1.length > 1) {
                    const needUpperWord = $1?.slice(1);
                    return $0?.replace($1, `${needUpperWord[0].toUpperCase()}${needUpperWord.slice(1)}`);
                }
                return $0;
            })
    );
}

export { normalizeContent, normalizeName };
